package com.learn.hmspring.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class Logg {

    @Pointcut("execution(* com.learn.hmspring.service..*.*(..))")
    public void pt1(){

    }

//    @Before("pt1()")
//    public void beforLog(){
//        System.out.println("前置通知");
//    }
//
//    @AfterReturning("pt1()")
//    public void  afterLog(){
//        System.out.println("后置通知");
//    }
//
//    @AfterThrowing("pt1()")
//    public void exeLog(){
//        System.out.println("异常通知");
//    }
//
//    @After("pt1()")
//    public void finLog(){
//        System.out.println("最终通知");
//    }

    @Around("pt1()")
    public Object aroundLog(ProceedingJoinPoint pjp){
        Object rtValue = null;
        Object[] args = pjp.getArgs();
        try {
            System.out.println("前置方法");
            rtValue = pjp.proceed(args);
            System.out.println("后置方法");
        } catch (Throwable throwable) {
            System.out.println("异常方法");
        }finally {
            System.out.println("最终方法");
        }

        return rtValue;
    }
}
